package com.example.demo.service.system;

import com.example.demo.dao.system.DictDAO;
import com.example.demo.model.system.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictService {
    @Autowired
    private DictDAO dao;

    public List<Dict> selectBySuperId(Integer super_id) {
        return dao.selectBySuperId(super_id);
    }

    public List<Dict> selectAll() {
        return dao.selectAll();
    }

    public Integer addDict(Dict dict) {
        return dao.addDict(dict);
    }

    public Integer deleteById(Integer dict_id) {
        return dao.deleteById(dict_id);
    }

    public Integer updateById(Dict dict) {
        return dao.updateById(dict);
    }

    public List<Dict> findDict(String title, String code, Integer super_id) {
        return dao.findDict(title, code, super_id);
    }

    public Boolean save(Dict dict) {
        Boolean flag = false;

        if (dict.getDict_id() != null) {
            flag = dao.updateById(dict) == 1;
        } else {
            flag = dao.addDict(dict) == 1;
        }

        return flag;
    }
}
